<?php
require_once("vcl/vcl.inc.php");
require_once("lib/db_connection.php");
//Includes
use_unit("components4phpfull/jtdivwindow.inc.php");
use_unit("components4phpfull/jtgroupbox.inc.php");
use_unit("components4phpfull/jtjavascript.inc.php");
use_unit("comctrls.inc.php");
use_unit("components4phpfull/jtsitetheme.inc.php");
use_unit("components4phpfull/jtdatepicker.inc.php");
use_unit("forms.inc.php");
use_unit("extctrls.inc.php");
use_unit("stdctrls.inc.php");

//Class definition
class Driving_History extends Page
{
       public $JTDivType = null;
       public $JTGroupBox1 = null;
       public $btnAddType = null;
       public $btnDelType = null;
       public $edType = null;
       public $listType = null;
       public $chkpersonalinjury = null;
       public $chkatfault = null;
       public $btnShowType = null;
       public $dpDate = null;
       public $cmbveh = null;
       public $Label6 = null;
       public $Label4 = null;
       public $memoComments = null;
       public $Label3 = null;
       public $edRefNum = null;
       public $Label2 = null;
       public $edCompLiability = null;
       public $Label1 = null;
       public $edPtAssessed = null;
       public $lblMobile = null;
       public $edDesc = null;
       public $cmbType = null;
       public $lblJob = null;
       public $lblBirthdate = null;
       public $imgBack = null;
       public $btnCancel = null;
       public $btnSubmit = null;
       public $JTJavaScript3 = null;
       public $JTJavaScript2 = null;
       public $JTJavaScript1 = null;
       public $compid = null;
       public $JTSiteTheme1 = null;
       public $hiddenDrivingHistory = null;
       public $hiddenEmpId = null;
       public $Image1 = null;
       function imgBackJSMouseOut($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.images['imgBack'].src="image/btn_back.png"
       <?php

       }

       function imgBackJSMouseOver($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.images['imgBack'].src="image/btn_back2.png"
       <?php

       }


       function btnDelTypeJSClick($sender, $params)
       {

       ?>
       //Add your javascript code here
       var TypeIndex = document.getElementById('listType').selectedIndex;
       var TypeValue = document.getElementById('listType')[TypeIndex].value;
       var comp = document.getElementById('compid').value;
       AjaxType3(TypeValue,comp);
       <?php

       }


       function btnAddTypeJSClick($sender, $params)
       {

       ?>
       //Add your javascript code here
       var addtype = document.getElementById('edType').value;
       var comp = document.getElementById('compid').value;
       AjaxType2(addtype,comp);
       document.Driving_History.edType.value = "";
       <?php

       }

       function btnShowTypeJSClick($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.getElementById('JTDivType').Show();
       document.Driving_History.edType.value = "";
       <?php

       }
       function btnSubmitClick($sender, $params)
       {
       if($this->chkpersonalinjury->Checked==true)
       {
       $personal_injury = '1';
       }
       else
       {
       $personal_injury = '0';
       }

       if($this->chkatfault->Checked==true)
       {
       $at_fault = '1';
       }
       else
       {
       $at_fault = '0';
       }

       $vehicle_id = $this->cmbveh->getItemIndex();
       $result_vehicle = mysql_query("SELECT * FROM vehicle_tbl WHERE vehicle_id='".$vehicle_id."'")
       or die("GET VEH_ID ".mysql_error());
       $row_veh = mysql_fetch_array($result_vehicle);


       mysql_query("update emp_drivinghistory_tbl set
       date ='".$this->dpDate->Text."',
       type ='".$this->cmbType->getItemIndex()."',
       description = '".$this->edDesc->Text."',
       point_assessed ='".$this->edPtAssessed->Text."',
       cost ='".$this->edCompLiability->Text."',
       ref_num ='".$this->edRefNum->Text."',
       comments ='".$this->memoComments->Text."',
       at_fault ='".$at_fault."',
       personal_injury ='".$personal_injury."',
       vehicle = '".$row_veh['veh_num'].' '.$row_veh['year'].''.$row_veh['manufacturer_name'].''.$row_veh['model_name']."',
       veh_id = '".$vehicle_id."'
       where emp_id='".$this->hiddenEmpId->getValue()."'and history_id ='".$this->hiddenDrivingHistory->getValue()."'")or die("UPDATE DRIVING HISTORY - " . mysql_error());

       redirect('personnel_driving_list.php?emp='.$this->hiddenEmpId->getValue());


       }

       function btnCancelClick($sender, $params)
       {
       redirect('personnel_driving_list.php?emp='.$this->hiddenEmpId->getValue().'&driving_history='.$this->hiddenDrivingHistory->getValue());


       }

       function Driving_HistoryCreate($sender, $params)
       {
       $this->compid->Value = $_SESSION['company_id'];
       $emp_id = $_GET['emp'];
       $driving_history = $_GET['driving_history'];
       $this->hiddenEmpId->setValue($emp_id);
       $this->hiddenDrivingHistory->setValue($driving_history);

       $this->imgBack->setLink('personnel_driving_list.php?emp='.$this->hiddenEmpId->getValue());

       $query_drive = "select * from emp_drivinghistory_tbl where emp_id='".$this->hiddenEmpId->getValue()."' and history_id='".$this->hiddenDrivingHistory->getValue()."'";
       $result_drive = mysql_query($query_drive)or die(mysql_error());
       $row_drive = mysql_fetch_array($result_drive);

       if($row_drive['at_fault']=="1")
       {
       $this->chkatfault->Checked=true;
       }
       else
       {
       $this->chkatfault->Checked=false;
       }


       if($row_drive['personal_injury']=="1")
       {
       $this->chkpersonalinjury->Checked=true;
       }
       else
       {
       $this->chkpersonalinjury->Checked=false;
       }


       $this->cmbveh->Clear();
       $this->cmbveh->AddItem('--Select--', null, null);
       $this->cmbveh->setItemIndex($row_drive['veh_id']);
       $result_veh = mysql_query("select * from vehicle_tbl where company_id='1'");

        while($row_veh = mysql_fetch_array($result_veh))
        {
            $this->cmbveh->AddItem($row_veh['veh_num'], null, $row_veh['vehicle_id']);
        }



       $this->cmbType->Clear();
       $this->cmbType->AddItem('--Select--', null, null);
       $this->cmbType->ItemIndex=$row_drive['type'];
       $result_type = mysql_query("select value from lookup_personnel_tbl where company_id= '".$_SESSION['company_id']."' AND category='driving history types'");

        while($row_type = mysql_fetch_array($result_type))
        {
            $this->cmbType->AddItem($row_type['value'], null, $row_type['value']);
        }

        //list type
       $result_t = mysql_query("select value from lookup_personnel_tbl where company_id='".$_SESSION['company_id']."' AND category='driving history types'");

        while($row_t = mysql_fetch_array($result_t))
        {
            $this->listType->AddItem($row_t['value'], null, $row_t['value']);
        }


       $this->dpDate->Text = $row_drive['date'];
       $this->edDesc->Text = $row_drive['description'];
       $this->edPtAssessed->Text = $row_drive['point_assessed'];
       $this->edCompLiability->Text = $row_drive['cost'];
       $this->edRefNum->Text = $row_drive['ref_num'];
       $this->memoComments->Text = $row_drive['comments'];


       }

}

global $application;

global $Driving_History;

//Creates the form
$Driving_History=new Driving_History($application);

//Read from resource file
$Driving_History->loadResource(__FILE__);

//Shows the form
$Driving_History->show();

?>